import axios from 'axios'

// let _userToken = sessionStorage.getItem('userToken')
// let _url = process.env.API_ROOT
// axios.defaults.baseURL = process.env.API_ROOT
const service = axios.create({

  // https://pay.renniting.cn/  赤峰正式环境

  // 'https://dev.renniting.cn/pay/';   赤峰测试环境

  baseURL: 'https://pay.renniting.cn/', // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 6000 // request timeout
})

service.interceptors.request.use(
  config => {
    // let token = _userToken
    // //let  token='298bd7ff-a025-4145-a4a3-554769375b48';
    // config.headers['X-Auth-Token'] = token
    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

// response interceptor
service.interceptors.response.use(
  response => {
    const res = response.data
    // if the custom code is not 20000, it is judged as an error.
    if (res.code != '8888') {
      return res
    } else {
      return res
    }
  },
  error => {
    console.log('err' + error) // for debug
    return Promise.reject(error)
  }
)

export default service
